import Vue from '@vitejs/plugin-vue';
import path from 'path';
import { defineConfig } from 'vite';
import Dts from 'vite-plugin-dts';
import Eslint from 'vite-plugin-eslint';

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    lib: {
      entry: ['./src/index.ts', './src/provider.ts'],
      name: 'mycomp',
      formats: ['es', 'cjs'],
      fileName: function (format, entry) {
        let fileType = 'js';
        if (format === 'es') fileType = 'mjs';
        if (entry.includes('provider')) return `provider.${fileType}`;
        else return `index.${fileType}`;
      },
    },
    rollupOptions: {
      external: ['vue', 'sortablejs', 'lodash-es', 'element-plus', 'decimal.js', '@element-plus/icons-vue'],
    },
  },
  plugins: [Vue(), Dts(), Eslint()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
    extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
  },
});
